package com.ruoyi.jpbi.controller.konggu;

import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.jpbi.domain.konggu.Jobs;
import com.ruoyi.jpbi.service.JobsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.ArrayList;
import java.util.List;

@Controller
@RequestMapping("/jpbi/jobs")
public class JobsController extends BaseController{
    private String prefix = "jpbi/konggu/jobs";
    @Autowired
    private JobsService jobsService;

    /**
     * 跳转分页页面
     */
    @GetMapping()
    public String user() {
        return prefix + "/jobs";
    }

    @RequestMapping("/getJobsList")
    @ResponseBody
    public TableDataInfo getJobsList(Jobs jobs) {
        startPage();
        List<Jobs> getJobsList = jobsService.findAllJobs(0+"","all",jobs);
        return getDataTable(getJobsList);
    }


    /**
     * 查看公司
     */
    @RequestMapping("/detail")
    public String detail(String id, ModelMap mmap) {
        mmap.put("jobs", jobsService.findJobsone(id));
        return prefix + "/details";
    }




    @RequestMapping("/editJobs")
    public String editDepa(String id, ModelMap mmap) {
        Jobs jobs = jobsService.findJobsone(id);
        mmap.put("jobs", jobs);
        return prefix + "/edit";
    }

    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult edit(Jobs jobs) {
        return toAjax(jobsService.updateJobs(jobs));
    }


    @GetMapping("/add")
    public String add(Jobs jobs) {
        return prefix + "/add";
    }

    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(Jobs jobs) {
        return toAjax(jobsService.insertJobs(jobs));
    }

    @RequestMapping("/remove")
    @ResponseBody
    public int remove(String alljobsID)
    {
        List<String> jobsList = new ArrayList<String>();
        String[] arry = alljobsID.split(",");
        for(int i=0;i<arry.length;i++){
            jobsList.add(arry[i]);
        }
        return jobsService.deleteJobs(jobsList);
    }




}
